<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>发送所有注册的并行调用</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="yar-concurrent-client.call.html">« Yar_Concurrent_Client::call</a></li>
      <li style="float: right;"><a href="yar-concurrent-client.reset.html">Yar_Concurrent_Client::reset »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.yar-concurrent-client.html">Yar_Concurrent_Client</a></li>
    <li>发送所有注册的并行调用</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="yar-concurrent-client.loop" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">Yar_Concurrent_Client::loop</h1>
  <p class="verinfo">(PECL yar &gt;= 1.0.0)</p><p class="refpurpose"><span class="refname">Yar_Concurrent_Client::loop</span> &mdash; <span class="dc-title">发送所有注册的并行调用</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-yar-concurrent-client.loop-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="modifier">static</span> <span class="methodname"><strong>Yar_Concurrent_Client::loop</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.callable.html" class="type callable">callable</a></span> <code class="parameter">$callback</code><span class="initializer"> = ?</span></span>, <span class="methodparam"><span class="type"><a href="language.types.callable.html" class="type callable">callable</a></span> <code class="parameter">$error_callback</code><span class="initializer"> = ?</span></span>): <span class="type">boolean</span></div>

  <p class="para rdfs-comment">
   发送所有的已经通过
   <span class="methodname"><a href="yar-concurrent-client.call.html" class="methodname">Yar_Concurrent_Client::call()</a></span>注册的并行调用, 并且等待返回.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-yar-concurrent-client.loop-parameters">
  <h3 class="title">参数</h3>
  <dl>
   
    <dt>
<code class="parameter">callback</code></dt>

    <dd>

     <p class="para">
      如果这个回掉函数被设置,
      那么Yar在发送出所有的请求之后立即调用一次这个回掉函数(此时还没有任何请求返回),
      调用的时候$callinfo参数是NULL.
     </p>
     <p class="para">
      如果在注册并行调用的时候制定了callback, 那么那个callback有更高的优先级.
     </p>
    </dd>

   
   
    <dt>
<code class="parameter">error_callback</code></dt>

    <dd>

     <p class="para">
      错误回掉函数, 如果设置了, 那么Yar在出错的时候会调用这个回掉函数.
     </p>
    </dd>

   
  </dl>

 </div>


 <div class="refsect1 returnvalues" id="refsect1-yar-concurrent-client.loop-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-yar-concurrent-client.loop-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="example-5361">
   <p><strong>示例 #1 <span class="function"><strong>Yar_Concurrent_Client::loop()</strong></span> example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">callback</span><span style="color: #007700">(</span><span style="color: #0000BB">$retval</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$callinfo</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(</span><span style="color: #0000BB">$callinfo&nbsp;</span><span style="color: #007700">==&nbsp;</span><span style="color: #0000BB">NULL</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"现在,&nbsp;所有的请求都发出去了,&nbsp;还没有任何请求返回\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;else&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"这是一个远程调用的返回,&nbsp;调用的服务名是"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$callinfo</span><span style="color: #007700">[</span><span style="color: #DD0000">"method"</span><span style="color: #007700">],&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">".&nbsp;调用的sequence是&nbsp;"&nbsp;</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$callinfo</span><span style="color: #007700">[</span><span style="color: #DD0000">"sequence"</span><span style="color: #007700">]&nbsp;,&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$retval</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />}&nbsp;<br /><br />function&nbsp;</span><span style="color: #0000BB">error_callback</span><span style="color: #007700">(</span><span style="color: #0000BB">$type</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$error</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$callinfo</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">error_log</span><span style="color: #007700">(</span><span style="color: #0000BB">$error</span><span style="color: #007700">);<br />}<br /><br /></span><span style="color: #0000BB">Yar_Concurrent_Client</span><span style="color: #007700">::</span><span style="color: #0000BB">call</span><span style="color: #007700">(</span><span style="color: #DD0000">"http://host/api/"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"some_method"</span><span style="color: #007700">,&nbsp;array(</span><span style="color: #DD0000">"parameters"</span><span style="color: #007700">),&nbsp;</span><span style="color: #DD0000">"callback"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">Yar_Concurrent_Client</span><span style="color: #007700">::</span><span style="color: #0000BB">call</span><span style="color: #007700">(</span><span style="color: #DD0000">"http://host/api/"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"some_method"</span><span style="color: #007700">,&nbsp;array(</span><span style="color: #DD0000">"parameters"</span><span style="color: #007700">));&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;if&nbsp;the&nbsp;callback&nbsp;is&nbsp;not&nbsp;specificed,&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;callback&nbsp;in&nbsp;loop&nbsp;will&nbsp;be&nbsp;used<br /></span><span style="color: #0000BB">Yar_Concurrent_Client</span><span style="color: #007700">::</span><span style="color: #0000BB">call</span><span style="color: #007700">(</span><span style="color: #DD0000">"http://host/api/"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"some_method"</span><span style="color: #007700">,&nbsp;array(</span><span style="color: #DD0000">"parameters"</span><span style="color: #007700">),&nbsp;</span><span style="color: #DD0000">"callback"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">NULL</span><span style="color: #007700">,&nbsp;array(</span><span style="color: #0000BB">YAR_OPT_PACKAGER&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">"json"</span><span style="color: #007700">));<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//this&nbsp;server&nbsp;accept&nbsp;json&nbsp;packager<br /></span><span style="color: #0000BB">Yar_Concurrent_Client</span><span style="color: #007700">::</span><span style="color: #0000BB">call</span><span style="color: #007700">(</span><span style="color: #DD0000">"http://host/api/"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"some_method"</span><span style="color: #007700">,&nbsp;array(</span><span style="color: #DD0000">"parameters"</span><span style="color: #007700">),&nbsp;</span><span style="color: #DD0000">"callback"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">NULL</span><span style="color: #007700">,&nbsp;array(</span><span style="color: #0000BB">YAR_OPT_TIMEOUT</span><span style="color: #007700">=&gt;</span><span style="color: #0000BB">1</span><span style="color: #007700">));<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//custom&nbsp;timeout&nbsp;<br /><br /></span><span style="color: #0000BB">Yar_Concurrent_Client</span><span style="color: #007700">::</span><span style="color: #0000BB">loop</span><span style="color: #007700">(</span><span style="color: #DD0000">"callback"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"error_callback"</span><span style="color: #007700">);&nbsp;</span><span style="color: #FF8000">//send&nbsp;the&nbsp;requests,&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//the&nbsp;error_callback&nbsp;is&nbsp;optional<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <div class="example-contents"><p>以上例程的输出类似于：</p></div>
   <div class="example-contents screen">
<div class="cdata"><pre>
现在, 所有的请求都发出去了, 还没有任何请求返回
这是一个远程调用的返回, 调用的服务名是some_method, 调用的sequence是 4
string(11) &quot;some_method&quot;
这是一个远程调用的返回, 调用的服务名是some_method, 调用的sequence是 1
string(11) &quot;some_method&quot;
这是一个远程调用的返回, 调用的服务名是some_method, 调用的sequence是 2
string(11) &quot;some_method&quot;
这是一个远程调用的返回, 调用的服务名是some_method, 调用的sequence是 3
string(11) &quot;some_method&quot;
</pre></div>
   </div>
  </div>
 </div>



 <div class="refsect1 seealso" id="refsect1-yar-concurrent-client.loop-seealso">
  <h3 class="title">参见</h3>
  <ul class="simplelist">
   <li class="member"><span class="methodname"><a href="yar-concurrent-client.call.html" class="methodname" rel="rdfs-seeAlso">Yar_Concurrent_Client::call()</a> - 注册一个并行的服务调用</span></li>
   <li class="member"><span class="methodname"><a href="yar-server.construct.html" class="methodname" rel="rdfs-seeAlso">Yar_Server::__construct()</a> - 创建一个HTTP RPC Server</span></li>
   <li class="member"><span class="methodname"><a href="yar-server.handle.html" class="methodname" rel="rdfs-seeAlso">Yar_Server::handle()</a> - 启动HTTP RPC Server</span></li>
  </ul>
 </div>


</div></div></div></body></html>